class Solution {
    public static int lengthOfLongestSubstring(String s) {
        int[] map = new int[128];
        int left = 0,right = 0,length = 0,len = 0;
        while(right < s.length()) {
            int j = s.charAt(right);
            map[j]++;
            if(map[j] > 1) {
                while(left <= right) {
                    int k = s.charAt(left);
                    map[k]--;
                    if(k == j) {
                        left++;
                        break;
                    }
                    left++;
                }
            }else {
                length = right - left + 1;
            }
            if(len < length) {
                len = length;
            }
            right++;
        }
        return len;
    }

    public static void main(String[] args) {
        int count = lengthOfLongestSubstring("tmmzuxt");
        System.out.println(count);
    }
}
